/*
 *  Copyright 2004 Blandware (http://www.blandware.com)
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package com.blandware.atleap.service.core;

import com.blandware.atleap.common.util.PartialCollection;
import com.blandware.atleap.common.util.QueryInfo;
import com.blandware.atleap.model.core.ContentImage;
import com.blandware.atleap.model.core.ContentResource;
import com.blandware.atleap.model.core.ResourceData;
import com.blandware.atleap.model.core.ContentDocument;
import com.blandware.atleap.persistence.exception.DeleteException;
import com.blandware.atleap.service.exception.BeanAlreadyExistsException;
import com.blandware.atleap.service.exception.BeanNotFoundException;
import com.blandware.atleap.service.exception.ContentLocaleNotFoundException;

import java.util.List;

/**
 * <p>Business Delegate (Proxy) Interface to handle communication between web and
 * persistence layer.
 * </p>
 * <p><a href="ContentResourceManager.java.html"><i>View Source</i></a>
 * </p>
 *
 * @author Sergey Zubtsovskiy <a href="mailto:sergey.zubtsovskiy@blandware.com">&lt;sergey.zubtsovskiy@blandware.com&gt;</a>
 * @author Andrey Grebnev <a href="mailto:andrey.grebnev@blandware.com">&lt;andrey.grebnev@blandware.com&gt;</a>
 * @version $Revision: 1.15 $ $Date: 2008/01/14 10:59:47 $
 */
public interface ContentResourceManager extends BaseManager {

	// C O N T E N T    R E S O U R C E S

	//~ CRUD Methods ================================================================

	/**
	 * Creates new content resource
	 *
	 * @param contentResource Content resource to create
	 * @param resourceData    resource data
	 * @return ID of created resource
	 * @throws BeanAlreadyExistsException if resource with same URI already exists
	 */
	public Long createContentResource(ContentResource contentResource, ResourceData resourceData) throws BeanAlreadyExistsException;

	/**
	 * Retrieves content resource with specified ID
	 *
	 * @param contentResourceId The ID of content resource to retrieve
	 * @return Content resource or null if no content resource with specified ID exists in database
	 */
	public ContentResource retrieveContentResource(Long contentResourceId);

	/**
	 * Updates content resource
	 *
	 * @param contentResource ContentResource to update
	 * @param resourceData    resource data
	 * @throws BeanAlreadyExistsException if resource with same name already exists
	 */
	public void updateContentResource(ContentResource contentResource, ResourceData resourceData) throws BeanAlreadyExistsException;

	/**
	 * Removes content resource
	 *
	 * @param contentResourceId ID of contentResource to remove
	 * @throws DeleteException if content resource cannot be deleted
     * @throws com.blandware.atleap.service.exception.BeanNotFoundException
     * if resource was not found
	 */
	public void deleteContentResource(Long contentResourceId) throws DeleteException, BeanNotFoundException;

	// ~ Additional methods ================================================================

	/**
	 * Retrieves filtered/sorted collection of content resources
	 *
	 * @param queryInfo Object that contains information about how to filter and sort data
	 * @return Collection of content resources
	 */
	public PartialCollection listContentResources(QueryInfo queryInfo);

	/**
	 * Retrieves no more than number of elements, specified in queryInfo's <code>limit</code> field.
	 *
	 * @param queryInfo Object that contains list of user roles and number of elements to return.
     * All of these are passed as query parameters: list of roles under key 'roles'.
     * Only resources that are allowed to view for some of the given roles are returned.
	 * @return List of content resources that correspond to <code>queryInfo</code>
	 */
	public List getLastContentResources(QueryInfo queryInfo);

    /**
	 * Increases usage counter to some value (can be negative)
	 *
	 * @param resourceId ID of content resource to update
     * @param value the value that will be added to usage counter
	 * @throws BeanNotFoundException if resource with this ID is not found
	 */
	public void increaseUsageCounter(Long resourceId, Integer value) throws BeanNotFoundException;

	// ~ Finders ================================================================

	/**
	 * Searches for content resource with specified URI
	 *
	 * @param uri URI to search by
	 * @return content resource or null if none has been found
	 */
	public ContentResource findContentResourceByUri(String uri);


	// C O N T E N T    I M A G E S

	//~ CRUD Methods ================================================================

	/**
	 * Creates new content image
	 *
	 * @param contentImage Content image to create
	 * @param resourceData resource data
	 * @return ID of created image
	 * @throws com.blandware.atleap.service.exception.BeanAlreadyExistsException
	 *          if image with same URI already exists
	 */
	public Long createContentImage(ContentImage contentImage, ResourceData resourceData) throws BeanAlreadyExistsException;

	/**
	 * Retrieves content image with specified ID
	 *
	 * @param contentImageId The ID of content image to retrieve
	 * @return Content image or null if no content image with specified ID exists in database
	 */
	public ContentImage retrieveContentImage(Long contentImageId);

	/**
	 * Updates content image
	 *
	 * @param contentImage ContentImage to update
	 * @param resourceData resource data
	 * @throws com.blandware.atleap.service.exception.BeanAlreadyExistsException
	 *          if image with same name already exists
	 */
	public void updateContentImage(ContentImage contentImage, ResourceData resourceData) throws BeanAlreadyExistsException;

	/**
	 * Removes content image
	 *
	 * @param contentImageId ID of content image to remove
	 * @throws com.blandware.atleap.persistence.exception.DeleteException
	 *          if content image cannot be deleted
     * @throws com.blandware.atleap.service.exception.BeanNotFoundException
     * if image was not found
	 */
	public void deleteContentImage(Long contentImageId) throws DeleteException, BeanNotFoundException;

	// ~ Additional methods ================================================================

	/**
	 * Retrieves filtered/sorted collection of content images
	 *
	 * @param queryInfo Object that contains information about how to filter and sort data
	 * @return Collection of content images
	 */
	public PartialCollection listContentImages(QueryInfo queryInfo);

	// ~ Finders ================================================================

	/**
	 * Searches for content image with specified URI
	 *
	 * @param uri URI to search by
	 * @return content image or null if none has been found
	 */
	public ContentImage findContentImageByUri(String uri);

    // C O N T E N T    D O C U M E N T S

    //~ CRUD Methods ================================================================

    /**
     * Creates new content document
     *
     * @param contentDocument Content document to create
     * @param resourceData resource data
     * @param localeIdentifier The identifier of content locale to associate with
     * this document
     * @return ID of created document
     * @throws com.blandware.atleap.service.exception.BeanAlreadyExistsException
     *          if document with same URI already exists
     * @throws com.blandware.atleap.service.exception.ContentLocaleNotFoundException
     * if requested content locale cound not be found
     */
    public Long createContentDocument(ContentDocument contentDocument, ResourceData resourceData, String localeIdentifier) throws BeanAlreadyExistsException, ContentLocaleNotFoundException;

    /**
     * Retrieves content document with specified ID
     *
     * @param contentDocumentId The ID of content document to retrieve
     * @return Content document or null if no content document with specified ID exists in database
     */
    public ContentDocument retrieveContentDocument(Long contentDocumentId);

    /**
     * Updates content document
     *
     * @param contentDocument ContentDocument to update
     * @param resourceData resource data
     * @param localeIdentifier The identifier of content locale to associate with
     * this document
     * @throws com.blandware.atleap.service.exception.BeanAlreadyExistsException
     *          if document with same name already exists
     * @throws com.blandware.atleap.service.exception.ContentLocaleNotFoundException
     * if requested content locale cound not be found
     */
    public void updateContentDocument(ContentDocument contentDocument, ResourceData resourceData, String localeIdentifier) throws ContentLocaleNotFoundException, BeanAlreadyExistsException;

    /**
     * Removes content document
     *
     * @param contentDocumentId ID of contentDocument to remove
     * @throws com.blandware.atleap.persistence.exception.DeleteException
     *          if content document cannot be deleted
     * @throws com.blandware.atleap.service.exception.BeanNotFoundException
     * if content document was not found
     */
    public void deleteContentDocument(Long contentDocumentId) throws DeleteException, BeanNotFoundException;

    // ~ Additional methods ================================================================

    /**
     * Retrieves filtered/sorted collection of content documents
     *
     * @param queryInfo Object that contains information about how to filter and sort data
     * @return Collection of content documents
     */
    public PartialCollection listContentDocuments(QueryInfo queryInfo);

    // ~ Finders ================================================================

    /**
     * Searches for content document with specified URI
     *
     * @param uri URI to search by
     * @return content document or null if none has been found
     */
    public ContentDocument findContentDocumentByUri(String uri);

}